package utils

import (
	"github.com/gogf/gf/frame/g"
)

const (
	TASK_QUEUE  = "task_queue"
	TASK_RESULT = "task_result"
	PROCESSING  = 2 // 正在生成
	FAILED      = 3 // 生成失败
	SUCCESS     = 4 // 生成成功
	CANCEL      = 5 // 取消
	QUEUED      = 6 // 排队中
)

func SetTaskGuidToRedis(taskId string, status int) {

	conn := g.Redis().Conn()
	defer conn.Close()
	conn.Do("SET", taskId, status)

}

func GetTaskGuidFromRedis(taskId string) (int, error) {
	conn := g.Redis().Conn()
	defer conn.Close()
	val, err := conn.DoVar("GET", taskId)
	if err != nil {
		return -1, err
	}
	return val.Int(), nil
}

func SetTaskResultToRedis(taskId string, result string) {
	conn := g.Redis().Conn()
	defer conn.Close()
	conn.Do("HSET", TASK_RESULT, taskId, result)
}

func GetTaskResultFromRedis(taskId string) (string, error) {
	conn := g.Redis().Conn()
	defer conn.Close()
	val, err := conn.DoVar("HGET", TASK_RESULT, taskId)
	if err != nil {
		return "", err
	}
	return val.String(), nil
}
